package com.company.behavioral.strategy_pattern.context;

import com.company.behavioral.strategy_pattern.strategy.Discount;

/**
 * 电影票类
 * @ClassName MovieTicket
 * @Author tiezheng.han
 * @Date 2020/9/7 15:33
 **/
public class MovieTicket {
    private double price;
    // 维持一个对抽象折扣类的引用
    private Discount discount;

    public void setPrice(double price) {
        this.price = price;
    }

    /**
     * 注入一个折扣类对象
     * @param discount
     */
    public void setDiscount(Discount discount) {
        this.discount = discount;
    }

    public double getPrice(){
        // 调用折扣类的折扣价格计算方法
        return discount.calculate(this.price);
    }
}
